<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");
	
	String _db = user.getDbType();
	
	
	Map<String,List<Map<String, String>>> dicMap = user.getDicMap();
	List<Map<String, String>> list = null;
	String temp = "";
	
	String tmadkind = "";//药具种类
	
	
	list = dicMap.get("105");
	tmadkind += "<option value=\"\"></option>";
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tmadkind += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/validata.js"></script>

		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerTree.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerForm.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerComboBox.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerDateEditor.js"></script>
<script type="text/javascript">
var _db = '<%=_db%>';

_jsonObj.classname = "com.wxtf.platform.main.contraceptives.ContraceptiveManagerAction";
_jsonObj.methodname = "queryPage";
var win;//添加药具

$(function(){
	_jsonObj.logicdata = getForm("query_form");
	manager = $("#mgrid").ligerGrid({
		url: _url, parms: _jsonObj, width: '100%', height: '100%',
		usePager: true, rownumbers: true, checkbox: true, alternatingRow: true,
		columns: [
			{ display: 'tmad_id', name: 'tmad_id', hide: true,width:1 },
			{ display: '药具种类', name: 'tmad_kind',width:150, align:'left',
			render: function(record, index, value, oth){
					<%
					list = dicMap.get("105");
					temp = "";
					if(null != list && list.size() > 0){
						for(Map<String, String> map: list){
					%>
					if(value == '<%=map.get("tmgd_id")%>'){
						<%
						temp = map.get("tmgd_name");
						%>
						return '<%=temp%>';
					}
					<%
						}
					}
					%>
					return value;
				}
			 },
			{ display: '药品名称', name: 'tmad_name', width: 150, align: 'left' ,
				render: function(record, index, value, oth){
					return " <a href='javascript:edit(" + JSON.stringify(record) + ")'>"+value+"</a>";
				}
				
			},
			{ display: '药品描述', name: 'tmad_description',  width:  1, hide:true },
			{ display: '药品规格', name: 'tmad_spec', width: 100, align: 'left' },
			{ display: '药品单位', name: 'tmad_unit', width: 150, align: 'left' },
			{ display: '生产厂家', name: 'tmad_company_name', width: 100, align: 'left' },
			{ display: '剂型', name: 'tmad_formulation',  width:  1, hide:true },
			{ display: '批号(药品编码)', name: 'tmad_batch_code', width: 100, align: 'left' },
			{ display: '保质期(月)', name: 'tmad_qgp', width: 100, align: 'left' },
			{ display: '药品状态', name: 'tmad_status', width: 100, align: 'left' ,
				render: function(record, index, value, oth){
					var str="";
					if(value == 0){
						str = "启用";
					}else{
						str = "停用";
					}
					return str;
				}
			},
			{ display: '每件内装', name: 'tmad_install', width: 100, align: 'left' },
			{ display: '价格', name: 'tmad_price', width: 100, align: 'left' },
			{ display: '备注', name: 'tmad_memo', width: 100, align: 'left' },
			{ display: '是否用于发放', name: 'reserve1', width: 100, align: 'left' ,
				render: function(record, index, value, oth){
					var str="";
					if(value == 1){
						str = "是";
					}else{
						str = "否";
					}
					return str;
				}
			},
			{ display: 'reserve2', name: 'reserve2', width:  1, hide:true },
			{ display: 'reserve3', name: 'reserve3', width:  1, hide:true },
			{ display: 'reserve4', name: 'reserve4', width:  1, hide:true },
			{ display: 'reserve5', name: 'reserve5', width:  1, hide:true },
			{ display: '录入人', name: 'create_by', width:  1, hide:true },
			{ display: '录入时间', name: 'create_time', width:  1, hide:true },
			{ display: '最后修改人', name: 'last_modify_by', width:  1, hide:true },
			{ display: '最后修改时间', name: 'last_modify_time', width: 1, hide:true },
			{ display: '编辑', name:'edit',width:60,render: function(record, index, value, oth){
					return "<img src='ligerUI/skins/icons/edit.gif' onclick='edit(" + JSON.stringify(record) + ")'></img>";
				}
			}
			
		],
		toolbar: {
			items: [
				{ text: '新建', click: function(){ addData(); }, icon: 'add' },
				{ line: true },
				{ text: '删除', click: function(){ delData(); },icon: 'delete'}
			]
		}
		
	}); 
});
/*
 * 条件查询
 */
function serch1(){
	$("#types").val("serch1");
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = getForm("query_form");  
	manager.loadData();
}
/*
 * 条件重置
 */
function serReset(){
	document.getElementById('query_form').reset();
}

/*
 * 表格刷新
 */
function reload(){
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = getForm("query_form");
	manager.loadData();
}

/*
 * ajax成功回调
 */
function ajaxCallbackSuccFunc(data, textStatus){
	win.hide();
	succMsgTip(data.resultrecord);
	reload();
}

/*
 * ajax失败回调
 */
function ajaxCallbackErrorFunc(data, textStatus){
	succMsgTip(data.resultrecord);
}

/*
 * 获取列表选中的药具ID
 */
function getIds(){
	var array = manager.getSelecteds();
	if(array.length == 0){
		return "";
	} else {
		var text = "";
		for(var i=0; i<array.length; i++){
			text += array[i].tmad_id + ",";
		}
		return text.substring(0, text.length - 1);
	}
}

/*
 * 新增药具
 */
function addData(){
	document.getElementById('mform').reset();
	$("#tmad_id").val('');
	if(win == null){
		win = initWindowByDiv('mdiv', '新建药具', 600, 350 ,save, closeWin);
	}else{
		win.show();
	}
}

/*
 * 修改药具
 */
function edit(row){
	document.getElementById('mform').reset();
	loadForm("mform", row);
	if(win == null){
		win = initWindowByDiv('mdiv', '新建药具', 600, 300 ,save, closeWin);
	}else{
		win.show();
	}
}
//四舍五入
function numFormat(a){
	var str = a;
	if(/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(str)&&str!=''){
		str = Math.round(parseFloat(str)*1000)/1000;
	}
	return str
}
/*
 * 新建/修改药具信息
 */
function save(){
	if(checkForm()){
		_jsonObj.logicdata = getForm("mform");
		var tmad_id = $("#tmad_id").val();
		if(tmad_id == ''){
			_jsonObj.methodname = "save";
			callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
		} else {
			_jsonObj.methodname = "update";
			callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
		}
	}
	
}
//校验表单
function checkForm(){
	var tmad_kind = $("#tmad_kind").val().trim();
	if(tmad_kind == ''){
		warningTip("药具种类：不能为空");
		return false;
	}
	
	var tmad_name = $("#tmad_name").val().trim();
	if(tmad_name == ''){
		warningTip("药品名称：不能为空");
		return false;
	}
	if(!checkIsString1(tmad_name)){
		warningTip("药品名称：必须为字母、数字、下划线、中文组成");
		return false;
	}
	if(fucCheckLength(tmad_name) > 64){
		warningTip("药品名称：不能超过64个字符");
		return false;
	}
	
	var tmad_spec = $("#tmad_spec").val().trim();
	if(fucCheckLength(tmad_spec) > 128){
		warningTip("药品规格：不能超过128个字符");
		return false;
	}
	if(!checkIsString(tmad_spec)){
		warningTip("药品规格：必须为字母、数字、下划线、中文组成");
		return false;
	}
	
	var tmad_unit = $("#tmad_unit").val().trim();
	if(fucCheckLength(tmad_unit) > 32){
		warningTip("药品单位：不能超过32个字符");
		return false;
	}
	if(!checkIsString(tmad_unit)){
		warningTip("药品单位：必须为字母、数字、下划线、中文组成");
		return false;
	}
	
	var tmad_company_name = $("#tmad_company_name").val().trim();
	if(fucCheckLength(tmad_company_name) > 128){
		warningTip("生产厂家：不能超过128个字符");
		return false;
	}
	if(!checkIsString(tmad_company_name)){
		warningTip("生产厂家：必须为字母、数字、下划线、中文组成");
		return false;
	}
	
	var tmad_batch_code = $("#tmad_batch_code").val().trim();
	if(fucCheckLength(tmad_batch_code) > 64){
		warningTip("批号：不能超过64个字符");
		return false;
	}
	if(!checkIsString(tmad_batch_code)){
		warningTip("批号：必须为字母、数字、下划线、中文组成");
		return false;
	}
	var tmad_memo = $("#tmad_memo").val().trim();
	if(fucCheckLength(tmad_memo) > 512){
		warningTip("备注：不能超过512个字符");
		return false;
	}
	if(!checkIsString(tmad_memo)){
		warningTip("备注：必须为字母、数字、下划线、中文组成");
		return false;
	}
	
	var tmad_install = $("#tmad_install").val().trim();
	if(fucCheckLength(tmad_install) > 11){
		warningTip("每件内装：不能超过11个字符");
		return false;
	}
	if(!isNum(tmad_install)){
		warningTip("每件内装：只能输入整字");
		return false;
	}
	
	var tmad_price = $("#tmad_price").val().trim();
	if(tmad_price == ''){
		warningTip("价格：不能为空");
		return false;
	}
	if(!isFloat(tmad_price)){
		warningTip("价格：必须为数字");
		return false;
	}
	if(tmad_price < 0 || tmad_price > 9999){
		warningTip("价格：不能为负数且不大于9999");
		return false;
	}
	
	var tmad_qgp = $("#tmad_qgp").val().trim();
	if(!isNum(tmad_qgp)){
		warningTip("保质期：必须为整数");
		return false;
	}
	if(fucCheckLength(tmad_qgp) > 3){
		warningTip("保质期：不能超过999");
		return false;
	}
	return true;
}




/*
 * 删除药具
 */
function delData(){
	var ids = getIds();
	if(ids == ""){
		warningTip('请至少选择一个药具进行操作');
		return;
	}
	$.ligerDialog.confirm('确定要删除选中的数据吗？（删除不可恢复）', function (opt) { 			
		if(opt){
			_jsonObj.methodname = "delete";
			_jsonObj.logicdata = "[{\"ids\":\"" + ids + "\"}]";
			callserver(_jsonObj, function(){ reload(); }, function(){});
		}
	});
}







</script>
	<body>
		<form id="query_form" name="query_form">
			<table id="aaa" class="serTable">
				<input type="hidden" id="types" name="types" value="init" />
				<tr>
					<td>药具名称：<input id="name_query" name="name_query"/></td>
					<td>药具种类：<select id="type_query" name="type_query">
						<%=tmadkind %>
					</select></td>
					<td>是否用于发放：
						<select id="reserve1_query" name="reserve1_query" >
							<option value="">全部</option>
							<option value="0">否</option>
							<option value="1">是</option>
						</select>
					</td>
					<td>药品状态：
							<select id="status_query" name="status_query" >
								<option value="">全部</option>
								<option value="0">启用</option>
								<option value="1">停用</option>
							</select>
					</td>
					<td><input class="btn2" value="搜索" type="button" onclick="serch1();" /></td>
					<td><input class="btn2" value="重置" type="button" onclick="serReset();" /></td>
				</tr>
			</table>
		</form>
		<div id="mgrid"></div>
		
		<div id="mdiv" style="display: none;">
			<form id="mform" name="mform">
				<input type="hidden" id="tmad_id" name="tmad_id" value="" />
				<input type="hidden" id="reserve2" name="reserve2" value="" />
				<input type="hidden" id="reserve3" name="reserve3" value="" />
				<input type="hidden" id="reserve4" name="reserve4" value="" />
				<input type="hidden" id="reserve5" name="reserve5" value="" />
				<input type="hidden" id="create_by" name="create_by" value="" />
				<input type="hidden" id="create_time" name="create_time" value="" />
				<input type="hidden" id="last_modify_by" name="last_modify_by" value="" />
				<input type="hidden" id="last_modify_time" name="last_modify_time" value="" />
				<input type="hidden" id="tmad_description" name="tmad_description" value="" />
				<input type="hidden" id="tmad_formulation" name="tmad_formulation" value="" />
				<table class="form_table">
					<tr>
						<td class="form_label">药具种类：</td>
						<td>
							<select id="tmad_kind" name="tmad_kind" style=" width: 182px;">
								<%=tmadkind %>
							</select>
						</td>
						<td><font color="red">*</font></td>
						
						<td class="form_label">药品名称：</td>
						<td><input class="textbg1" id="tmad_name" name="tmad_name" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td><font color="red">*</font></td>
					</tr>
					<tr>
						<td class="form_label">药品规格：</td>
						<td><input class="textbg1" id="tmad_spec" name="tmad_spec" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
						<td></td>
						<td class="form_label">药品单位：</td>
						<td><input class="textbg1" id="tmad_unit" name="tmad_unit" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">生产厂家：</td>
						<td><input class="textbg1" id="tmad_company_name" name="tmad_company_name" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
						<td></td>
						<td class="form_label">批号：</td>
						<td><input class="textbg1" id="tmad_batch_code" name="tmad_batch_code" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">每件内装：</td>
						<td><input class="textbg1" id="tmad_install" name="tmad_install" value="0" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
						<td></td>
						<td class="form_label">价格：</td>
						<td><input class="textbg1" id="tmad_price" name="tmad_price" onblur="this.value=numFormat(this.value)" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
						<td><font color="red">*</font></td>
					</tr>
					<tr>
						<td class="form_label">保质期(月)：</td>
						<td><input class="textbg1" id="tmad_qgp" name="tmad_qgp" value="0" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
						<td></td>
						<td class="form_label">药品状态：</td>
						<td>
							<select id="tmad_status" name="tmad_status" style=" width: 182px;" >
								<option value="0">启用</option>
								<option value="1">停用</option>
							</select>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">用于发放：</td>
						<td align="left" id="reserve1">
							<input style="margin-top: 2px; margin-left: 5px;" type="radio" name="reserve1" value="1"  />是
							<input style="margin-top: 2px; margin-left: 5px;" type="radio" name="reserve1" value="0" checked="checked"/>否
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">备注：</td>
						<td colspan="5">
						<textarea class="textbg3" id="tmad_memo" name="tmad_memo" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" style="height: 60px;width: 460px"></textarea>
						<td></td>
					</tr>
					<tr><td><br /></td></tr>
				</table>
			</form>
		</div>
	</body>
</html>
